
package main;

import java.awt.*;

public final class SplashWindow extends javax.swing.JWindow {
    
    private class GraphicsPanel extends javax.swing.JPanel {

        @Override
        protected void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            int x = 0;
            for(int i = 0; i < SplashWindow.COLORS.length; i++) {
                g2.setColor(SplashWindow.COLORS[i]);
                g2.fillRect(x, 0, 20, 319);
                x += 23;
            }

            g2.setPaint(new LinearGradientPaint(0.0F, 0.0F, 319F, 319F, new float[] {
                Math.max(0.0F, percentageComplete * 1.2F - 0.2001F), Math.min(1.0F, percentageComplete * 1.2F + 0.001F)
            }, new Color[] {
                new Color(255, 255, 255, 0), Color.WHITE
            }, java.awt.MultipleGradientPaint.CycleMethod.NO_CYCLE));
            g2.fillRect(0, 0, 319, 319);
            g2.drawImage(splashText, 0, 40, this);
        }

        private GraphicsPanel() {
            setBackground(Color.WHITE);
        }
    }


    public SplashWindow() {
        graphicsPanel = new GraphicsPanel();
        percentageComplete = 0.0F;
        splashText =  getIconImage("splash/splash3.png");
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(graphicsPanel, "Center");
        pack();
        setSize(319, 300);
        setLocationRelativeTo(null);
    }

    public void setPercentageComplete(float percentageComplete) {
        this.percentageComplete = Math.min(1.0F, Math.max(0.0F, percentageComplete));
        repaint();
    }

    private static final Color COLORS[] = {
        new Color(255, 212, 3), new Color(255, 177, 0), new Color(255, 109, 0), new Color(255, 2, 7), new Color(172, 3, 36), new Color(238, 4, 65), new Color(255, 116, 182), new Color(156, 145, 221), new Color(96, 140, 213), new Color(124, 178, 238), 
        new Color(162, 211, 254), new Color(65, 156, 157), new Color(0, 181, 174), new Color(2, 191, 3)
    };
    private Image splashText;
    private GraphicsPanel graphicsPanel;
    private float percentageComplete;


    public java.awt.Image getIconImage(String urlimagen) {
        java.awt.Image retValue = java.awt.Toolkit.getDefaultToolkit().
                getImage(ClassLoader.getSystemResource(urlimagen));
        return retValue;
    }

}
